<script setup>
import { ref } from "vue";
import { ElMessage } from "element-plus";
import { getStudentInfoService, updateStudentService } from "@/api/student.js";
import useUserStore from "@/stores/userStore.js";
import {
  getTeacherInfoService,
  getTeacherPersonalInfoService,
  updateTeacherService,
} from "@/api/teacher.js";
const teacherInfo = ref({
  teacherId: "",
  username: "",
  password: "",
  teacherName: "",
  status: "",
  collegeId: "",
  collegeName: "",
  categoryId: 1,
  userId: "",
  email: "",
});
const userStore = useUserStore();
const findByUserName = async () => {
  let username = userStore.info.username;
  let result = await getTeacherPersonalInfoService(username);
  teacherInfo.value = result.data;
};
findByUserName();
const updateTeacherInfo = async () => {
  let updateResult = await updateTeacherService(teacherInfo.value);
  if (updateResult.code === 0) {
    ElMessage.success("更新成功");
    await findByUserName();
  } else {
    ElMessage.error(updateResult.message);
  }
};
</script>

<template>
  <el-card class="page-container">
    <template #header>
      <div class="header">
        <span>基本资料</span>
      </div>
    </template>
    <el-row>
      <el-col :span="12">
        <el-form :model="teacherInfo" label-width="100px" size="large">
          <el-form-item label="教师ID">
            <el-input v-model="teacherInfo.teacherId" disabled></el-input>
          </el-form-item>
          <el-form-item label="用户ID">
            <el-input v-model="teacherInfo.userId" disabled></el-input>
          </el-form-item>
          <el-form-item label="用户名">
            <el-input v-model="teacherInfo.username" disabled></el-input>
          </el-form-item>
          <el-form-item label="姓名">
            <el-input v-model="teacherInfo.teacherName"></el-input>
          </el-form-item>
          <el-form-item label="状态">
            <el-input v-model="teacherInfo.status" disabled></el-input>
          </el-form-item>
          <el-form-item label="学院">
            <el-input v-model="teacherInfo.collegeName" disabled></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="teacherInfo.email"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="updateTeacherInfo"
              >提交修改</el-button
            >
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </el-card>
</template>

<style scoped></style>
